home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / examples / keep < prev    next >
Encoding:
Text File  |  1994-02-08  |  2.1 KB  |  86 lines

  1. #!/usr/local/bin/icmake -qi
  2.  
  3. /*
  4.     Sample Icmake script. This program deletes all files except for the
  5.     ones mentioned on the command line. Uses "rm" and "rm -r" for the
  6.     actual deletion of files.
  7.     
  8.     For the installation: see the sample file 'tolower'.
  9. */
  10.  
  11. #define VER "1.00"
  12.  
  13. int
  14.     recursive;                    // remove subdirs too?
  15.     
  16. void checkfiles (list files)            // check that the files
  17. {                        // are present
  18.     int
  19.         i;                    // loop counter
  20.     string
  21.         file;                    // one file from list
  22.         
  23.     for (i = 0; i < sizeof (files); i++)
  24.     {
  25.         file = element (i, files);        // get 1 filename
  26.         stat (file);                // stat file.. if this fails,
  27.     }                        // Icmake will exit
  28. }
  29.  
  30. void keep (list files)                // remove all but the 
  31. {                        // files
  32.     int
  33.         i;                    // loop counter
  34.     list
  35.         dir;                    // dir listing
  36.     string
  37.         recursive_flag;                // recursive flag for 
  38.                             // "rm"
  39.                             
  40.     if (recursive)                // set recursive flag
  41.         recursive_flag = "-r";            // if needed
  42.         
  43.     checkfiles (files);                // make sure files are
  44.                             // there
  45.     if (recursive)
  46.         dir = makelist (O_ALL, "*");        // make dir listing
  47.     else                    //  with subdirs if 
  48.         dir = makelist ("*");            //  recursive processing
  49.         
  50.     dir -= files;                // scratch files to keep
  51.     
  52.     for (i = 0; i < sizeof (dir); i++)        // for each file in dir:
  53.         exec ("rm", recursive_flag,         // remove it
  54.               element (i, dir));
  55. }
  56.  
  57. void main (int argc, list argv)
  58. {
  59.     if (element (1, argv) == "-r")        // check first flag
  60.     {
  61.         recursive++;
  62.         argv -= (list) element (1, argv);
  63.     }
  64.     
  65.     if (! element (1, argv))            // print usage if no args
  66.     {
  67.         printf ("\n"
  68.             "ICCE Directory Cleaner  V", VER, "\n"
  69.             "Copyright (c) ICCE, 1993. All rights reserved.\n"
  70.             "\n"
  71.             "Usage: keep [-r] file(s)\n"
  72.             "where:\n"
  73.             "      -r      - optional flag; specifies recursive"
  74.                                 " processing\n"
  75.             "      file(s) - files or subdirectories to keep, others"
  76.                                 " are deleted\n"
  77.         "\n");
  78.     exit (1);
  79.     }
  80.     
  81.     argv -= (list) element (0, argv);        // remove makefile from args
  82.     keep (argv);                // and.. do it to it
  83.     
  84.     exit (0);
  85. }
  86.